<!doctype html>
<html  class="x-admin-sm" lang="ch">
<head>
    <meta charset="UTF-8">
    <title>后台注册</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>
    <script type="text/javascript" src="js/cookie.js"></script>
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">后台注册</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form">
        <input id="id" name="id" placeholder="用户名"  type="text" lay-verify="id" class="layui-input" >
        <hr class="hr15">
        <input id="password" name="password" lay-verify="password" placeholder="密码"  type="password" class="layui-input">
        <hr class="hr15">
        <input id="password2" name="password" lay-verify="password" placeholder="确认密码"  type="password" class="layui-input">
        <hr class="hr15">
        <button type="button" id="submit" style="background-color: #009688;margin-left: auto;width: 100%;height: 40px;font-size: medium;color: white">注册</button>
        <hr class="hr20" >
        <a href="login.html">已有账号？去登录</a>
    </form>
</div>

<script>
    $(function() {
        $("#submit").click(function () {
            var id=$("#id").val();
            var password=$("#password").val();
            var password2=$("#password2").val();
            $.ajax({
                url: "http://localhost:8080/user/add",
                dataType:"json",
                type:"post",
                contentType : "application/json; charset=utf-8",
                data: JSON.stringify({"id":id,"password":password,"password2":password2}),
                success:function () {
                    window.location.href="login.html";
                },
                error:function () {
                    alert("error");
                }
            });
        });
        // layui.use('form', function(){
        //     var form = layui.form;
        //     var $ = layui.$;
        //     form.on('submit(login)', function(data){
        //         var url = "http://localhost:8080/user/doLogin/"
        //             + data.field.username + "/" + data.field.password;
        //         $.post(url,null,function (data) {
        //             location.href='index.html'
        //             }
        //         ).fail(function (jqXHR) {
        //             layer.msg(jqXHR.responseText);
        //         });
        //         return false;
        //   });
        // });
    });
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        //自定义验证规则
        form.verify({
            id: function(value){
                if(value === '' || value === null){
                    return '账号不能为空';
                }
            }
            ,password: function(value){
                if(value === '' || value === null){
                    return '密码不能为空';
                }
            }
        });
    });
</script>
</body>
</html>